import {
  MiddlewareConsumer,
  Module,
  NestModule,
  RequestMethod,
} from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ValidateRequestHeaderMiddleware } from './validate-request-header/validate-request-header.middleware';
import { DbService } from './db/db.service';
import { HashService } from './hash/hash.service';
import { ConfigModule } from '@nestjs/config';

@Module({
  controllers: [AppController],
  providers: [AppService, DbService, HashService],
  imports: [ConfigModule.forRoot()],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    if (process.env.NODE_ENV === 'development') {
      return;
    }

    consumer.apply(ValidateRequestHeaderMiddleware).forRoutes(
      {
        path: 's',
        method: RequestMethod.POST,
      },
      {
        path: 'p',
        method: RequestMethod.POST,
      },
    );
  }
}
